package com.sykj.cloud.activity.controller;

import com.sykj.cloud.activity.domain.ActivityInfo;
import com.sykj.cloud.activity.service.IActivityInfoService;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.web.page.TableDataInfo;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.log.enums.LogUserType;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 活动信息Controller
 *
 * @author mr.will
 * @date 2021-04-01
 */
@RestController
@RequestMapping("/info")
public class ActivityInfoController extends BaseController
{
    @Autowired
    private IActivityInfoService activityInfoService;

    /**
     * 新增活动信息
     */
    @PreAuthorize(hasPermi = "activity:info:add")
    @Log(title = "活动信息", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityInfo activityInfo)
    {
        return toAjax(activityInfoService.insertActivityInfo(activityInfo));
    }

    /**
     * 修改活动信息
     */
    @PreAuthorize(hasPermi = "activity:info:edit")
    @Log(title = "活动信息", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityInfo activityInfo)
    {
        return toAjax(activityInfoService.updateActivityInfo(activityInfo));
    }

    /**
     * 删除活动信息
     */
    @PreAuthorize(hasPermi = "activity:info:remove")
    @Log(title = "活动信息", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(activityInfoService.deleteActivityInfoByIds(guids));
    }

    /**
     * 获取活动信息详细信息
     */
    @PreAuthorize(hasPermi = "activity:info:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(activityInfoService.getActivityInfoById(guid));
    }

    /**
     * 导出活动信息列表
     */
    @PreAuthorize(hasPermi = "activity:info:export")
    @Log(title = "活动信息", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityInfo activityInfo) throws IOException
    {
        List<ActivityInfo> list = activityInfoService.listActivityInfos(activityInfo);
        ExcelUtil<ActivityInfo> util = new ExcelUtil<ActivityInfo>(ActivityInfo.class);
        util.exportExcel(response, list, "info");
    }

    /**
    * 查询活动信息列表
    */
    @PreAuthorize(hasPermi = "activity:info:list")
    @GetMapping("/list")
        public TableDataInfo list(ActivityInfo activityInfo)
    {
        startPage();
        List<ActivityInfo> list = activityInfoService.listActivityInfos(activityInfo);
        return getDataTable(list);
    }
    }
